package com.zbkj.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zbkj.dal.base.enums.RecyclePositionEnums;
import com.zbkj.dal.entity.ba.BizImg;
import com.zbkj.dal.dao.BizImgMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zbkj.service.service.BizImgService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 业务图片(共享，回收等） 服务实现类
 * </p>
 *
 * @author jhui
 * @since 2023-10-03
 */
@Service
public class BizImgServiceImpl extends ServiceImpl<BizImgMapper, BizImg> implements BizImgService {

    @Override
    public Boolean deleteByBizId(Integer type, Integer bizId) {
        LambdaQueryWrapper<BizImg> queryWrapper = Wrappers.lambdaQuery(BizImg.class);
        queryWrapper.eq(BizImg::getType, type).eq(BizImg::getBizId, bizId);
        return remove(queryWrapper);
    }

    @Override
    public List<BizImg> listByBizId(Integer type, Integer bizId) {
        LambdaQueryWrapper<BizImg> queryWrapper = Wrappers.lambdaQuery(BizImg.class);
        queryWrapper.eq(BizImg::getType, type).eq(BizImg::getBizId, bizId);
        return list(queryWrapper);
    }

    @Override
    public List<BizImg> listByBizIds(Integer type, List<Integer> bizIds) {
        LambdaQueryWrapper<BizImg> queryWrapper = Wrappers.lambdaQuery(BizImg.class);
        queryWrapper.eq(BizImg::getType, type).in(BizImg::getBizId, bizIds);
        return list(queryWrapper);
    }

    @Override
    public BizImg listByBizIdsAndPosition(Integer type, Integer bizIds, RecyclePositionEnums position) {
        LambdaQueryWrapper<BizImg> queryWrapper = Wrappers.lambdaQuery(BizImg.class);
        queryWrapper.eq(BizImg::getType, type);
        queryWrapper.eq(BizImg::getPosition, position.getCode());
        queryWrapper.eq(BizImg::getBizId, bizIds);
        return getOne(queryWrapper);
    }

    @Override
    public List<BizImg> listByBizIdsAndPosition(List<Integer> types, List<Integer> bizIds, RecyclePositionEnums position) {
        LambdaQueryWrapper<BizImg> queryWrapper = Wrappers.lambdaQuery(BizImg.class);
        queryWrapper.in(BizImg::getType, types);
        queryWrapper.eq(BizImg::getPosition, position.getCode());
        queryWrapper.in(BizImg::getBizId, bizIds);
        return list(queryWrapper);
    }

    @Override
    public BizImg getOneByBizId(Integer type, Integer bizId, RecyclePositionEnums position) {
        LambdaQueryWrapper<BizImg> queryWrapper = Wrappers.lambdaQuery(BizImg.class);
        queryWrapper.eq(BizImg::getType, type);
        queryWrapper.eq(BizImg::getPosition, position.getCode());
        queryWrapper.eq(BizImg::getBizId, bizId);
        return getOne(queryWrapper);
    }
}
